
const fs = require('fs');
const processError = require('../../common/error');

// 往目标文件夹中写入wiki文件
module.exports = function(option,callback){

  let {filePath,gdprAdminPath,gdprExtPath,version,md5sum,user,branch,memo} = option;

  let size = 0;
  let gdprAdminVersion = '';
  let gdprExtVersion = '';
  try {
    size = parseInt(fs.statSync(filePath+'.tar').size/1024);
    gdprAdminVersion = fs.readFileSync(gdprAdminPath,'utf-8');
    gdprExtVersion = fs.readFileSync(gdprExtPath,'utf-8');
  } catch (error) {
    processError('获取文件大小错误');
  }
//   let content = `
// | 版本号  | ${moduleName}  | 打包时间   | MD5校验值     | 固件大小     | 打包人     | 分支     | 备注     |
// | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
// | ${version}   | ${version}   | ${new Date().Format('yyyy-MM-dd HH:mm:ss')}     |  ${md5sum}    |  ${size}    |  ${user}    |   ${branch}   |   ${memo}   |
// `
  let content=`||**版本号**||**打包日期**||**MD5**||**打包人**||**分支**||**固件大小**||**gdbr**||**备注**||
  || ${version} || ${new Date().Format('yyyy-MM-dd HH:mm:ss')} || ${md5sum} || ${user} || ${branch} || ${size}KB || admin：${gdprAdminVersion || ''}; ext：${gdprExtVersion || ''} || ${memo || '打包信息'} ||`
  fs.writeFileSync(filePath+'.wiki',content);

  option.filePath = filePath+'.wiki';

  console.log(`\n${content}\n`);
  
  if(callback instanceof Function)callback(option);
}